package org.syncsoft.overalt.gui.api.window;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.JLabel;
import javax.swing.JTable;

import org.syncsoft.overalt.common.api.Resource;
import org.syncsoft.overalt.domain.community.entity.Community;
import org.syncsoft.overalt.gui.impl.componentPlugin.TableCommunityComponentPlugin;
import org.syncsoft.overalt.gui.util.BuildFormWindow;

/**
 * 
 * @author tptfc
 *
 */
public abstract class AbstractSendFileWindow extends AbstractWindow {
	private Collection<Community> communities;
	
	public AbstractSendFileWindow(AbstractWindowController<?> controller) {
		super(controller);
	}

	public AbstractSendFileWindow(int width, int height, AbstractWindowController<?> controller) {
		super(width, height, controller);
	}

	@Override
	protected void buildWindow() {
		setTitle(Resource.getProperty("overalt.label.addFile"));
		BuildFormWindow build = new BuildFormWindow(getPanel());
		doBuildWindow(build);
	}
	
	protected void doBuildWindow(BuildFormWindow build) {
		JLabel label;

		label = new JLabel(Resource.getProperty("overalt.label.title"));
		build.add(label, newTextField("title"));
		
		label = new JLabel(Resource.getProperty("overalt.label.description"));
		build.add(label, newTextArea("description"));
		
		label = new JLabel(Resource.getProperty("overalt.label.restriction"));
		Collection<String> items = new ArrayList<String>();
		items.add(Resource.getProperty("overalt.label.public"));
		items.add(Resource.getProperty("overalt.label.private"));
		build.add(label, newComboBox("permission", items));
		
		label = new JLabel(Resource.getProperty("overalt.label.tags"));
		build.add(label, newTextField("tags"));
		
		label = new JLabel(Resource.getProperty("overalt.label.communities"));
		build.add(label, newCommunitiesTable("associetedCommunities", getCommunities()));
		
		addSaveAndCancelButtons(build);
	}
	
	/**
	 * 
	 * @param key
	 * @param communities
	 * @return
	 */
	protected JTable newCommunitiesTable(String key, Collection<Community> communities) {
		TableCommunityComponentPlugin component = getComponentPlugin(TableCommunityComponentPlugin.class);
		return component.newTable(key, communities);
	}

	//	GETs AND SETs
	public Collection<Community> getCommunities() {
		return communities;
	}
	public void setCommunities(Collection<Community> communities) {
		this.communities = communities;
	}
}
